#include "rf433.h"
#include "cmsis_os2.h"
#include "usart.h"
#include "myprintf.h"
USART6_RECEIVETYPE Usart6_Type;
USART6_RECEIVETYPE usart6_rx;
extern osMessageQueueId_t myQueue04Handle;

void USART6_RxIdleCallback(UART_HandleTypeDef *huart)
{
	if ((__HAL_UART_GET_FLAG(huart,UART_FLAG_IDLE) != RESET)) {
		__HAL_UART_CLEAR_IDLEFLAG(huart);
		HAL_UART_DMAStop(huart);
		Usart6_Type.RX_Size = USART6_LEN - huart->hdmarx->Instance->NDTR;
		/************************************************************************************/
		if (Usart6_Type.RX_Size <= USART6_LEN)
			osMessageQueuePut(myQueue04Handle, &Usart6_Type, 0U, 0U);
//		HAL_UART_Transmit(&huart3, &Usart6_Type.RX_pData[0], Usart6_Type.RX_Size, 0xFFFF);
		memset(&Usart6_Type.RX_pData, 0x00, Usart6_Type.RX_Size);
		/************************************************************************************/
		__HAL_UART_CLEAR_OREFLAG(huart);
		HAL_UART_Receive_DMA(huart, &Usart6_Type.RX_pData[0], USART6_LEN);
	}
}


void usart6_rx_deal(USART6_RECEIVETYPE *usart6_rx)
{
	HAL_UART_Transmit(&huart3, &usart6_rx->RX_pData[0], usart6_rx->RX_Size, 0xFFFF);
}
void rf433_reset(void)
{
	HAL_GPIO_WritePin(BF1_433RST_GPIO_Port, BF1_433RST_Pin, GPIO_PIN_RESET);
	osDelay(2000);
	HAL_GPIO_WritePin(BF1_433RST_GPIO_Port, BF1_433RST_Pin, GPIO_PIN_SET);
	osDelay(1000);
}
void rf433_deal(void)
{
	rf433_reset();
	while(1) {
		uint8_t data[20] = {0xAA, 0x00, 0x0C, 0xAA, 0x55, 0x00, 0x04, 0x31, 0x00};
		HAL_UART_Transmit(&huart6, &data[0], 9, 0xFFFF);
		osDelay(3000);

	}




}

